package guru.kafka.test;

import kafka.utils.VerifiableProperties;

import java.util.Map;

/**
 * Created by xufei on 16/10/13.
 */
public class HashPartitioner implements kafka.producer.Partitioner {

    public HashPartitioner(VerifiableProperties verifiableProperties) {}

    @Override
    public int partition(Object key, int numPartitions) {
        if (key instanceof Integer) {
            return Math.abs(Integer.parseInt(key.toString())) % numPartitions;
        }
        return Math.abs(key.hashCode() % numPartitions);
    }
}
